package com.nanako.mapper;

import com.nanako.bean.Student;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface StudentMapper {
    @Results(id = "StuMapper",value = {
            @Result(column = "hire_date", property = "hirDate")
    })
    @Select("select * from stu")
    List<Student> selectAll();

    @Select("select * from stu where id = #{id}")
    @ResultMap("StuMapper")
    Student selectById(int id);

    @Select("<script>" +
            "select * from stu" +
            " <where>" +
            " <if name != null> name = #{name} </if>" +
            " <if gender != null> and gender = #{gender} </if>" +
            " <if address != null> and address = #{address} </if>" +
            "</where>" +
            "</script>")
    @ResultMap("StuMapper")
    Student selectByCondition(Student student);
}
